home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / scrnmasm.arc / SCREEN.ASM < prev    next >
Assembly Source File  |  1988-11-20  |  8KB  |  181 lines

  1.      DosSeg
  2.      .XList
  3.      .Model Small
  4.      .Code
  5.      Include Save.Mac
  6.      Include Restore.Mac
  7.      Include SkipLine.Mac
  8.      Public WriteCharUsingBios,WriteCharToScreen,ColorAttribute,NextLine
  9.      Public ClearScreen,HideCursor,RestoreCursor
  10.      Page  ,132
  11.      .Sall
  12. ColorAttribute db 0                     ; Screen color
  13. ScreenWidth    db 79                    ; Screen width-1
  14. ScreenHeight   db 24                    ; Screen height-1
  15. CursorSize     dw 0607h                 ; Cursor setup
  16.      .List
  17.      Title Write a character to the screen
  18. ;
  19. ; This procedure will output a byte to the screen using a BIOS/Color
  20. ; output function.
  21. ; -------------------------------------------------------------------
  22. ; Input: AL=Character to output          Output: None
  23. ;        ColorAttribute=Color value
  24. ;
  25. WriteCharToScreen Proc Near
  26.          Save  CX                      ; Save register
  27.          Mov   AH,ColorAttribute       ; Get the color
  28.          Call  WriteCharUsingBios      ; Output the character
  29.          Call  BiosAdvanceCursor       ; And move the cursor
  30.          Restore CX                    ; Restore value
  31.          Ret                           ; Return to caller
  32. WriteCharToScreen Endp
  33. ;
  34. ; This procedure will write to the screen (first page, one byte only)
  35. ; -------------------------------------------------------------------
  36. ; Input: AL=Character                    Output: None
  37. ;        AH=ColorAttribute
  38. ;
  39. WriteCharUsingBios Proc Near
  40.          Save  BX,CX                   ; Save registers
  41.          Xor   BH,BH                   ; Use the first page
  42.          Mov   BL,AH                   ; Get the attribute
  43.          Mov   CX,1                    ; Don't repeat
  44.          Mov   AH,9                    ; Function for the write
  45.          Int   10h                     ; Call BIOS
  46.          Restore BX,CX                 ; Restore registers
  47.          Ret                           ; Return to caller
  48. WriteCharUsingBios Endp
  49. ;
  50. ; This procedure will advance the cursor one position to the right
  51. ;------------------------------------------------------------------
  52. ; Input: None                           Output: None
  53. ;
  54. BiosAdvanceCursor Proc Near
  55.          Save  DX                      ; Save register
  56.          Call  GetCursorPosition       ; Get the current position
  57.          Call  GetNextCursorPosition   ; Point to the next one
  58.          Call  PositionCursor          ; And position the cursor
  59.          Restore DX                    ; Restore register
  60.          Ret                           ; Return to caller
  61. BiosAdvanceCursor Endp
  62. ;
  63. ; This procedure will get the ROW/COLUMN where the cursor resides
  64. ; ---------------------------------------------------------------
  65. ; Input: None                            Output: DH=ROW, DL=COLUMN
  66. ;
  67. GetCursorPosition Proc Near
  68.          Save  AX,BX                   ; Save values
  69.          Mov   AH,3                    ; Function for get cursor
  70.          Xor   BX,BX                   ; On this page
  71.          Int   10h                     ; Call BIOS
  72.          Restore AX,BX                 ; Restore values
  73.          Ret                           ; Return to caller
  74. GetCursorPosition Endp
  75. ;
  76. ; This procedure will calculate the next row/column to place the
  77. ; cursor after a character has been output.
  78. ; --------------------------------------------------------------
  79. ; Input: DH=ROW                         Output: DH=NEXT ROW
  80. ;        DL=COLUMN                              DL=NEXT COLUMN
  81. ;
  82. GetNextCursorPosition  Proc Near
  83.          Inc   DL                      ; Point to the next column
  84.          Cmp   DL,ScreenWidth          ; Is it the last column ?
  85.          Jna   Short CalcDone          ; No..it's O.K.
  86.          Sub   DL,ScreenWidth          ; Get the next lines column
  87.          Dec   DL                      ; Bit of a kludge here
  88.          Cmp   DH,ScreenHeight         ; Are we at the bottom ?
  89.          Jnb   AtTheBottom             ; Yes...
  90.          Inc   DH                      ; Point to the next row
  91.          Jmp   CalcDone                ; And exit
  92. AtTheBottom:
  93.          SkipLines 1                   ; Go down a line
  94.          Xor   DL,DL                   ; Reset column
  95. CalcDone:
  96.          Ret                           ; Return to caller
  97. GetNextCursorPosition  Endp
  98. ;
  99. ; This procedure will move the cursor to a new position
  100. ; -----------------------------------------------------
  101. ; Input: DH=ROW                        Output: None
  102. ;        DL=COLUMN
  103. ;
  104. PositionCursor Proc Near
  105.          Save  AX,BX                   ; Save registers
  106.          Xor   BX,BX                   ; First video page
  107.          Mov   AH,2                    ; MoveCursor function
  108.          Int   10h                     ; Call BIOS
  109.          Restore AX,BX                 ; Restore values
  110.          Ret                           ; Return to caller
  111. PositionCursor Endp
  112. ;
  113. ; This procedure will skip a line for scrolling
  114. ; ---------------------------------------------
  115. ; Input: None                          Output: None
  116. ;
  117. NextLine Proc Near
  118.          Save  AX,BX,CX,DX             ; Save registers
  119.          Mov   AH,6                    ; Function for scrolling
  120.          Mov   AL,1                    ; Scroll 1 line
  121.          Mov   CH,0                    ; Column 1
  122.          Mov   CL,0                    ; Row 1
  123.          Mov   BH,colorattribute       ; Using the current color
  124.          Mov   DH,24                   ; Row 25
  125.          Mov   DL,79                   ; Column 80
  126.          Int   10h                     ; Call BIOS
  127.          Restore AX,BX,CX,DX           ; Restore all registers
  128.          Ret                           ; Return to caller
  129. NextLine Endp
  130. ;
  131. ; This procedure will clear the screen
  132. ; --------------------------------------------------------
  133. ; Input: ColorAttribute                 Output: None
  134. ;
  135. ClearScreen Proc Near
  136.          Save    AX,BX,CX,DX           ; Save registers
  137.          Mov     AH,15                 ; Function for get video mode
  138.          Int     10h                   ; Put in the values
  139.          Xor     AH,AH                 ; Function for set video mode
  140.          Int     10h                   ; Call BIOS
  141.          Xor     BH,BH                 ; Indicate BG/Border setup
  142.          Mov     BL,ColorAttribute     ; Get the color in use
  143.          Mov     CX,4                  ; Setup for bit shifting
  144. FlipBits:
  145.          Shr     BX,1                  ; Strip off the FG bits
  146.          Loop    FlipBits              ; (4 of them)
  147.          Mov     AH,11                 ; Function for set color palette
  148.          Int     10h                   ; Call BIOS
  149.          Restore AX,BX,CX,DX           ; Restore values
  150.          Ret                           ; Return to caller
  151. ClearScreen Endp
  152. ;
  153. ; This procedure will save the current cursor type and hide the cursor
  154. ; --------------------------------------------------------------------
  155. ; Input: None                           Output: CursorSize
  156. ;
  157. HideCursor Proc Near
  158.          Save  AX,BX,CX,DX             ; Save registers
  159.          Call  GetCursorPosition       ; Get the current type
  160.          Mov   CursorSize,CX           ; And save it
  161.          Mov   CX,2020h                ; This size should hide it
  162.          Mov   AH,1                    ; Function for setting cursor
  163.          Int   10h                     ; Call BIOS
  164.          Restore AX,BX,CX,DX           ; Restore values
  165.          Ret                           ; Return to caller
  166. HideCursor Endp
  167. ;
  168. ; This procedure will UNDO what HideCursor did
  169. ; ----------------------------------------------------
  170. ; Input: CursorSize                       Output: None
  171. ;
  172. RestoreCursor Proc Near                ; Unhide the cursor
  173.          Save  AX,CX                   ; Save registers
  174.          Mov   CX,CursorSize           ; Get the original size
  175.          Mov   AH,1                    ; Function for setting it
  176.          Int   10h                     ; Call Bios
  177.          Restore AX,CX                 ; Restore registers
  178.          Ret                           ; Return to caller
  179. RestoreCursor Endp
  180.          End
  181.